﻿namespace TSL.Utility
{
    using System;
    using System.IO;
    using System.Web;

    internal class Request
    {
        private HttpContext context;
        private string m_RequestType;
        private string m_URL;

        public Request(HttpContext context, string requestType, string url)
        {
            this.context = context;
            this.m_RequestType = requestType;
            this.m_URL = url;
        }

        public string ApplicationPath
        {
            get
            {
                string applicationPath = this.context.Request.ApplicationPath;
                if (applicationPath.Equals("/"))
                {
                    return "";
                }
                return applicationPath;
            }
        }

        public string Extension
        {
            get
            {
                return System.IO.Path.GetExtension(this.m_URL).ToLower();
            }
        }

        public string FileName
        {
            get
            {
                return System.IO.Path.GetFileName(this.m_URL).ToLower();
            }
        }

        public string FileNameWithoutExtension
        {
            get
            {
                return System.IO.Path.GetFileNameWithoutExtension(this.m_URL).ToLower();
            }
        }

        public string FilePath
        {
            get
            {
                return this.context.Request.FilePath;
            }
        }

        public string FilePathWithoutExtension
        {
            get
            {
                return this.FilePath.Substring(0, this.FilePath.Length - this.Extension.Length);
            }
        }

        public string Path
        {
            get
            {
                return this.FilePath.Substring(this.ApplicationPath.Length, (this.FilePath.Length - this.ApplicationPath.Length) - this.FileName.Length).Trim(new char[] { '/' });
            }
        }

        public string PhysicalApplicationPath
        {
            get
            {
                return this.context.Request.PhysicalApplicationPath;
            }
        }

        public string PhysicalPath
        {
            get
            {
                return this.context.Request.PhysicalPath;
            }
        }

        public string PhysicalPathWithoutExtension
        {
            get
            {
                return this.PhysicalPath.Substring(0, this.PhysicalPath.Length - this.Extension.Length);
            }
        }

        public string VirtualFilePath
        {
            get
            {
                return this.FilePathWithoutExtension.Substring(this.ApplicationPath.Length);
            }
        }

    }
}